
import { login } from '@/api/user.js'
import { settoken, gettoken, removetoken } from '@/utils/storage'
import { Toast } from 'vant'
import router from '@/router'
export default {
  namespaced: true,
  state: {
    token: gettoken() || ''
  },
  mutations: {
    dotoken (state, payload) {
      state.token = payload
      settoken(payload)
    },
    deltoken (state) {
      state.token = ''
      removetoken()
    }
  },
  actions: {
    async getlogin (content, payload) {
      const res = await login(payload)
      console.log(res);
      if (res.errno === 0) {
        Toast.success('登录成功')
        router.push(`/user`)
        content.commit('dotoken', res.data.token)
      } else {
        Toast.fail(res.errmsg)
      }

    }
  },
  getters: {},
  modules: {}
}